package lookas.foto;

import java.io.File;
import java.util.Calendar;
import java.util.Date;

import lookas.track.GPSPosition;

import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.lang.CompoundException;
import com.drew.metadata.Directory;
import com.drew.metadata.exif.ExifDirectory;

public class FotoPosition extends GPSPosition {
	private File foto;

	public FotoPosition(File foto, long timedelta) throws CompoundException {
		this.foto = foto;
		this.date = Calendar.getInstance();
		this.date.setTimeInMillis(FotoPosition.readDate(foto).getTime()
				+ timedelta);
		this.date.add(Calendar.HOUR, 1);
	}

	@Override
	public String toString() {
		return foto.getName() + ": " + super.toString();
	}

	public File getFoto() {
		return foto;
	}

	public static Date readDate(File foto) throws CompoundException {
		Directory directory = JpegMetadataReader.readMetadata(foto)
				.getDirectory(ExifDirectory.class);
		return directory.getDate(ExifDirectory.TAG_DATETIME_ORIGINAL);
	}

	public void writeGPSPosition() {
		// TODO
	}
}
